const { createHobby,findHobbies,delHobby } = require("../model/hobbyModel");

//新增
const addHobby = async (req, res, next) => {
  const result = await createHobby(req.body);
  if (result) {
    res.send({ httpStatus: 200, data: result, msg: "增加成功" });
  } else {
    res.send({ httpStatus: 400, data: [], msg: "增加出错" });
  }
};
//查询
const getHobbies = async (req, res) => {
  const result = await findHobbies(req.query);
  if (result.length || result.length === 0) {
    res.send({ httpStatus: 200, total: result.length, data: result });
  } else {
    res.send({ httpStatus: 400, msg: "查询出错", date: [] });
  }
};

//删除
const deleteHobby = async (req, res) => {
  const { _id } = req.query;
  const query = { _id };
  const result = await delHobby(query);
  if (result.n) {
    res.send({ httpStatus: 200, state: true, msg: "删除成功" });
  } else {
    res.send({ httpStatus: 400, state: false, msg: "删除出错" });
  }
};


module.exports = {
  addHobby,
  getHobbies,
  deleteHobby,
};
